var boardMixin = function (hasDeptWork) {
  if (hasDeptWork === undefined) {
    hasDeptWork = true;
  }

  var option = {
    data: function () {
      return {
        deptWorkName: null
      };
    },

    methods: {
      setDeptWorkName: function (deptWork, user) {
        if (deptWork.length === 0) {
          this.deptWorkName === '';
          return Promise.resolve(user);
        }

        var deptId = deptWork[0];
        if (deptId !== undefined && deptId.indexOf('-') !== -1) {
          deptId = deptId.split('-')[1];
        }

        var self = this;
        if (deptWork.length === 1) {
          return ajaxRequest('basicData/getDeptName').then(function (deptList) {
            deptId = Number(deptId);
            var dept = _.find(deptList, {
              id: deptId
            });
            self.deptWorkName = dept.deptName;
          });
        }

        var workshopId = deptWork[1];
        if (workshopId !== undefined && workshopId.indexOf('-') !== -1) {
          workshopId = workshopId.split('-')[1];
        }
        return ajaxRequest('basicData/getWorkshopName', {
          deptId: deptId
        }).then(function (workshopList) {
          var workshop = _.find(workshopList, {
            id: workshopId
          });
          if (workshop === undefined) {
            self.deptWorkName = '';
          } else {
            self.deptWorkName = `${workshop.productionLine} - ${workshop.workshopName}`;
          }
          return user;
        });
      }
    }
  };

  var deptWorkFun = function () {
    var search = this.search;
    if (search === null) {
      return null;
    }

    var deptWork = search.deptWork;
    if (SysUtil.isEmpty(deptWork)) {
      return null;
    }

    var obj = {};
    for (var i = 0; i < deptWork.length; i++) {
      var deptWorkStr = deptWork[i];
      var array = deptWorkStr.split('-');
      obj[array[0]] = array[1];
    }
    return obj;
  };

  if (hasDeptWork) {
    _.set(option, 'computed.deptWork', deptWorkFun);
  }

  return option;
};
